﻿using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Pitaya_IDE
{
    public class SubPanel:Panel
    {
        private List<SubPanel> subPanelList;
        public FileTitleBar fileTitleBar;
        private MainPanel mainPanel;
        private Form1 form1;
        private bool focus1 = false;  //表示当前面板是否拥有焦点  若没有就要把panel改不高亮
        public double WidthPropn;

        public DisplayPanel displayPanel;

        public bool Focus1
        { 
            get => focus1;
            set {
                if (value)
                {
                    foreach (SubPanel subPanel in subPanelList)
                    {
                        if(!subPanel.Equals(this))
                            subPanel.Focus1 = false;
                    }
                }
                focus1 = value;
                fileTitleBar.Focus1 = value;
            }
        }

        //public SubPanel(Inode inode, List<SubPanel> _subPanelList, MainPanel _mainPanel,Form1 _form1)
        //{
        //    subPanelList = _subPanelList;
        //    mainPanel = _mainPanel;
        //    form1 = _form1;

        //    BackColor = mainPanel.BackColor;
        //    WidthPropn = 1 / ((double)_subPanelList.Count + 1);

        //    //这里  子面板要先初始化文档编辑器  否则网络文件到了，
        //    //显示面板都还没初始化完毕
        //    displayPanel = new DisplayPanel(this, inode);
        //    fileTitleBar = new FileTitleBar(mainPanel, this);

        //    this.Controls.Add(fileTitleBar);

        //    //AddTitle(inode);

            

        //    Controls.Add(displayPanel);

        //    Focus1 = true;
        //}
        //public void AddTitle(Inode inode)
        //{
        //    fileTitleBar.AddTitlePanel(inode);
        //}

        public void RefreshLocation()
        {
            for (int i = 0; i < subPanelList.Count; i++)
            {
                if (subPanelList[i].Equals(this))
                {
                    RefreshLocation(i);
                }
            }
        }
        public void RefreshLocation(int cnt)
        {
            //两种情况
            //this是第一个
            //this不是第一个

            int w = mainPanel.Size.Width;
            int h = mainPanel.Size.Height;

            

            if (subPanelList[0].Equals(this))//this是第一个
            {
                this.Location = new Point(0, 0);
                w = (int)(WidthPropn * w) ;
            }
            else  //this不是第一个
            {
                int left = subPanelList[cnt-1].Left + subPanelList[cnt - 1].Width + 1;
                this.Location = new Point(left, 0);

                w = (int)(WidthPropn * w) - 1;
            }

            Size = new Size(w, h);
            displayPanel.RefreshLocation(w, h);

            /*内部组件大小计算*/
            fileTitleBar.Location = new Point(0, 0);
            fileTitleBar.Size = new Size(Width, 60);
            fileTitleBar.RefreshLabel();
        }
    }

    public class DisplayPanel : Panel
    {
        private SubPanel subPanel;
        public FastColoredTextBox fctb;
        private DocumentMap documentMap1;
        //public DisplayPanel(SubPanel _subPanel, Inode inode)
        //{
        //    subPanel = _subPanel;

        //    Location = new Point(0, 38 + 60);
        //    Size = new Size(subPanel.Width, subPanel.Height - (38 + 60));
        //    BackColor = subPanel.BackColor;

        //    fctb = new FastColoredTextBox
        //    {
        //        AutoCompleteBracketsList = new char[] { '(', ')', '{', '}', '[', ']', '\"', '\"', '\'', '\'' },
        //        AutoIndentCharsPatterns = "\r\n^\\s*[\\w\\.]+(\\s\\w+)?\\s*(?<range>=)\\s*(?<range>[^;=]+);\r\n^\\s*(case|default)\\s*[^:]*(?<range>:)\\s*(?<range>[^;]+);\r\n",
        //        AutoScrollMinSize = new Size(1138, 5385),
        //        BackBrush = null,
        //        BracketsHighlightStrategy = BracketsHighlightStrategy.Strategy2,
        //        CharHeight = 15,
        //        CharWidth = 7,
        //        Cursor = Cursors.IBeam,
        //        DisabledColor = Color.FromArgb(100, 180, 180, 180),
        //        Dock = DockStyle.Fill,
        //        IsReplaceMode = false,
        //        Language = Language.CSharp,
        //        LeftBracket = '(',
        //        LeftBracket2 = '{',
        //        Name = "fctb",
        //        Paddings = new Padding(0),
        //        RightBracket = ')',
        //        RightBracket2 = '}',
        //        ServiceColors = new ServiceColors(),
        //        TabIndex = 2,
        //        Zoom = 100,


        //        SelectionColor = Color.FromArgb(100, 40, 100, 170),//被选中的颜色
        //        ServiceLinesColor = Color.FromArgb(28, 33, 39),//代码块的线颜色
        //        Font = new Font("Consolas", 16F),//字体
        //        ForeColor = Color.FromArgb(201, 209, 217),//文字颜色
        //        LineNumberColor = Color.FromArgb(139, 148, 158),//左边行号颜色
        //        BackColor = BackColor,//背景色
        //        IndentBackColor = BackColor,//行号背景色
        //        Location = new Point(0, 0),
        //        Size = new Size(Size.Width - 120, Size.Height),
        //        //Text = strdata  //文字内容
        //    };

        //    Controls.Add(fctb);

        //    documentMap1 = new DocumentMap
        //    {
        //        Dock = DockStyle.Right,
        //        ForeColor = Color.FromArgb(55, 70, 80),
        //        Location = new Point(Size.Width - 120, 0),
        //        Name = "documentMap1",
        //        Size = new Size(120, Size.Height),
        //        TabIndex = 1,
        //        Target = fctb,
        //        Text = "documentMap1"
        //    };

        //    Controls.Add(documentMap1);
        //}

        public void RefreshLocation(int w, int h)
        {
            Size = new Size(w, h - (38 + 60));
            fctb.Size = new Size(Size.Width - 120, Size.Height);
            documentMap1.Location = new Point(Size.Width - 120, 0);
            documentMap1.Size = new Size(120, Size.Height);
        }

        private string strdata = @"using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Pitaya_IDE
{
    public class SubPanel:Panel
    {
		public SubPanel(Inode inode,Form1 _form1)
        {
            int data;
        }

        /// <summary>
        /// Collection of Hints.
        /// This is temporary buffer for currently displayed hints.
        /// </summary>
        public void RefreshLocation(int cnt)
        {
            //两种情况
            //this是第一个
            //this不是第一个

            int w = mainPanel.Size.Width;
            int h = mainPanel.Size.Height;

            

            if (subPanelList[0].Equals(this))//this是第一个
            {
                this.Location = new Point(0, 0);
                w = (int)(WidthPropn * w) ;
            }
            else  //this不是第一个
            {
                int left = subPanelList[cnt-1].Left + subPanelList[cnt - 1].Width + 1;
                this.Location = new Point(left, 0);

                w = (int)(WidthPropn * w) - 1;
            }

            this.Size = new Size(w, h);


            /*内部组件大小计算*/
            fileTitleBar.Location = new Point(0, 0);
            fileTitleBar.Size = new Size(Width, 60);
            fileTitleBar.RefreshLabel();
            //fileTitleBar.RefreshCnt();
        }
	}
}";
    }
}